//
//  HMTableViewController.m
//  MusicPlayer
//
//  Created by 王龙飞 on 15/9/29.
//  Copyright © 2015年 王龙飞. All rights reserved.
//

#import "HMTableViewController.h"
#import "HMMusic.h"
#import "UIImage+image.h"
#import "HMPlayingViewController.h"
@interface HMTableViewController ()

/**音乐数组*/
@property (nonatomic, strong) NSArray *musicArr;
/**正在播放的界面控制器*/
@property (nonatomic, strong) HMPlayingViewController *playingVC;

@end

@implementation HMTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.rowHeight = 80;
}

#pragma mark - 懒加载
- (NSArray *)musicArr
{
    if (_musicArr == nil) {
        
        _musicArr = [HMMusic musics];
    }
    
    return _musicArr;
}

- (HMPlayingViewController *)playingVC
{
    if (_playingVC == nil) {
        
        _playingVC = [[HMPlayingViewController alloc] init];
    }
    
    return _playingVC;
}

#pragma mark - Table view data source

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.playingVC show];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.musicArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //创建cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    //获取模型数据
    HMMusic *musicM = self.musicArr[indexPath.row];
    
    //给cell赋值
    cell.textLabel.text = musicM.name;
    cell.detailTextLabel.text = musicM.singer;
    //随机颜色
    UIColor *randomColor =  [UIColor colorWithRed:((float)arc4random_uniform(256)/255.0) green:((float)arc4random_uniform(256)/255.0) blue:((float)arc4random_uniform(256)/255.0) alpha:1.0];
    cell.imageView.image = [UIImage imageWithBorderW:3 color:randomColor image:[UIImage imageNamed:musicM.singerIcon]];
    
    //返回cell
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
@end
